import store from '@/store';
import {DOMAINS} from "./config.js"
const types = ['POST', 'GET', 'DELETE', 'PUT', 'CONNECT', 'HEAD', 'OPTIONS', 'TRACE'];
const baseURL =DOMAINS.CUNW
const timeout = 10000;
const request = {};
console.log('process.env.NODE_ENV :>> ', process.env.NODE_ENV);
types.forEach((item) => {
  const type = item.toLocaleLowerCase();
  request[type] = (url, data,header,extra) => new Promise((resolve) => {
    uni.request({
      url: `${baseURL}/${url}`,
      data,
      method: item,
      header:{...header,token: store.state.auth.token}
	  //其他带过来的配置
      ...extra,
      // eslint-disable-next-line no-shadow
      success: ({ data }) => {
        resolve(data);
      },
      fail: (error) => {
        resolve({
          message: JSON.stringify(error),
        });
      },
      // eslint-disable-next-line no-shadow
      complete: ({ data }) => {
        resolve(data);
      },
    });
  });
});
export default { ...request };
